

package io.kerns.boot.lock;

import java.io.Serializable;

/**
 * 全局锁枚举
 *
 */
public enum GlobalLockType implements Serializable {

    TMP_TEST("TMP_TEST"),
    ;

    private static final long serialVersionUID = 1L;
    private String name;

    private static ThreadLocal<String> threadLocal=new ThreadLocal();

    private GlobalLockType(String name) {
        this.name = name;
    }

    /**
     * 如果是多线程情况下，会导致parameter 脏读的问，所以使用ThreadLocal 处理这个问题
     * @param parameter
     * @return
     */
    public GlobalLockType setParameter(String parameter) {
        threadLocal.set(parameter);
        return this;
    }

    public String getParameter() {
        String parameter= threadLocal.get();
        return null == parameter ? "" : parameter;
    }
}
